package com.lry.web.cartoon.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lry.web.cartoon.entity.CartoonChapter;
import com.lry.web.cartoon.mapper.CartoonChapterMapper;
import com.lry.web.cartoon.service.CartoonChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@Service
public class CartoonChapterServiceImpl implements CartoonChapterService {
    @Autowired
    CartoonChapterMapper cartoonChapterMapper;




    public int setCartoonChapter(CartoonChapter cartoonChapter) {
        int insert = cartoonChapterMapper.insert(cartoonChapter);
        return insert;
    }


    public List<CartoonChapter> getCartoonChapters(String cartoonId) throws IOException {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("cartoon_id",cartoonId);
        List<CartoonChapter> cartoonChapters = cartoonChapterMapper.selectList(wrapper);
        return cartoonChapters;

    }



    public int deleteByCVId(String cVId) throws Exception {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("cartoon_variable_id",cVId);

        return cartoonChapterMapper.delete(wrapper);
    }

    public int deleteByCartoonId(String cartoonId) throws Exception {
        List<String> listCId = Arrays.asList(cartoonId.split(","));
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("cartoon_id",listCId);

        return cartoonChapterMapper.delete(wrapper);
    }


}

